<template>
    <div class="goodsrent">
        <el-table :data="rentReq.rentReqList" style="width: 100%" @selection-change="selhandle">
            <el-table-column prop="Userid" label="学号" width="150" />
            <el-table-column prop="Create_time" label="起始时间" />
            <el-table-column prop="Currten_time" label="截止时间" />
            <el-table-column prop="Currinvent" label="当前库存" width="150" />
            <!-- <el-table-column prop="Id" label="是否同意租借?">
                <template #default="scope">
                    <el-popconfirm title="确认租借?" @confirm="agreeRent(scope.row.Id)">
                        <template #reference>
                            <el-button type="success">同意</el-button>
                        </template>
                    </el-popconfirm>
                </template>
            </el-table-column> -->
            <el-table-column prop="Isacceptornot" label="管理员是否同意租借?">
                <template #default="scope">
                    <span>
                        {{ scope.row.Isacceptornot == "0" ? '未同意' : '已同意' }}
                    </span>
                </template>
            </el-table-column>
            <el-table-column prop="Id" label="是否撤销请求?" width="150">
                <template #default="scope">
                    <el-button type="primary" @click="isCancel(scope.row.Id)">
                        是
                    </el-button>
                </template>
            </el-table-column>
            <el-table-column prop="Id" label="是否归还?" width="150">
                <template #default="scope">
                    <!-- v-if="scope.row.Isacceptornot == '' ? false : true" -->
                    <el-button type="success" @click="isReturn(scope.row.Id)"
                        :disabled="scope.row.Isacceptornot == '0' ? true : false">
                        是
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script setup>
import { ref, reactive, toRefs } from 'vue';
import { useRoute, useRouter } from "vue-router";
import { rentRequestsApi, returnApi, cancelApi } from "../request/api"
import { rentReqStore } from "../store/rentReq";
// Create_time: "2023-03-23T10:27:02+08:00"
// Currinvent: 99
// Currten_time: "2023-03-30T10:27:02+08:00"
// Isacceptornot: ""
// Id: 3 订单唯一标识
// Orderid: 0
// Userid: 2

// rentReqId returnApi的参数
// rentReqId cancelApi的参数
const Router = useRouter();
const Route = useRoute();
const rentReq = reactive(rentReqStore());
rentRequestsApi().then(res => {
    console.log(res);
    rentReq.addrentReqList(res);
});

// 选中操作
const selhandle = (val) => {
    console.log(val);
}
// 归还请求
const isReturn = (val) => {
    console.log(val);
    returnApi({
        rentReqId: val
    }).then(res => {
        console.log(res);
        if (res.askData.prompt) {
            ElMessage({
                message: res.askData.prompt,
                type: 'success'
            })
        }
    })
}
// 撤销请求
const isCancel = (val) => {
    console.log(val);
    cancelApi(val).then(res => {
        console.log(res);
        if (res.askData.prompt == "err") {
            ElMessage({
                message: "撤销失败！",
                type: 'error'
            })
        }
    })
}

</script>
 
<style lang = "less" scoped>
:deep(.el-table .cell) {
    text-align: center;
}

// is-leaf
:deep(.el-table .is-leaf .cell) {
    color: #000;
    font-weight: 700;
}
</style>